package com.elm.mapper;

import com.elm.po.Cart;
import com.elm.po.Food;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FoodMapper {
	@Select("select * from food where business_id=#{businessId} And status='available'")
    List<Food> getAvailableFoodByBusinessId(Integer businessId);
	
	@Select("select * from food where business_id=#{businessId}")
    List<Food> getAllFoodByBusinessId(Integer businessId);
    
    @Select("select * from food where status='reviewing'")
    List<Food> getAllReviewingFood();
    
    int updateReviewingFoodInfo(Integer foodId, String status);
    
//    @Update("Update food set food_name=#{foodName},food_explain=#{foodExplain},food_img=#{foodImg},food_price=#{foodPrice},remarks=#{remarks},status=#{status} where id=#{id}")
//    int updateFoodInfo(Food food);
    
    @Insert("INSERT INTO food (" +
	        "creator,  " +
	        "food_explain, food_img, " +
	        "food_name, food_price, remarks, " +
	        "business_id" +
	        ") VALUES (" +
	        " #{creator}," +
	        "#{foodExplain}, #{foodImg}, #{foodName}, " +
	        "#{foodPrice}, #{remarks}, #{businessId} " +
	        ")")
    int createFood(Food food);
    
    @Update("Update food set status=#{status} where id=#{id}")
    int updateFoodStatus(int id,String status);
    
    @Select("select * from food where food_name=#{foodName} ANd business_id=#{businessId}")
	Food getFoodByNameByBusiness(String foodName, Integer businessId);
    
    @Select("select * from food where id=#{id}")
	Food getFoodById(int id);
    
    @Select("SELECT f.* FROM food f " +
            "INNER JOIN orderdetailet od ON f.id = od.food_id " +
            "WHERE od.order_id = #{orderId}")
    List<Food> getFoodByOrderId(Integer orderId);
} 